package com.gis507.test.CsvSplit;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.checkerframework.checker.units.qual.C;

import java.io.IOException;

public class CsvSplitMapper extends Mapper<LongWritable, Text,Text,CsvBean> {

    private Text outK = new Text();
    private CsvBean outV = new CsvBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1
        String line = value.toString();

        //2
        // 1,jeryy,18,male,1
        String[] csvComments = line.split(",");

        //3
        String id = csvComments[0];
        String name = csvComments[1];
        String age = csvComments[2];
        String sex = csvComments[3];
//        CsvBean bean = new CsvBean(id, name, age, sex);

        //4
        outV.setId(id);
        outV.setName(name);
        outV.setAge(age);
        outV.setSex(sex);

        outK.set(id);

        //5
        context.write(outK,outV);

    }
}
